package com.itht.baoleme.config;

import com.itht.baoleme.domain.web.WebCodeEnum;
import com.itht.baoleme.domain.web.WebServiceException;
import com.itht.baoleme.domain.web.WebServiceMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
@Slf4j
public class ControllerExceptionAdvice {

    @ResponseBody
    @ExceptionHandler(WebServiceException.class)
    public WebServiceMessage webServiceExceptionHandler(WebServiceException e) {
        log.error("警告！！！程序出现异常", e);
        return e.getWebMessage();
    }


    @ResponseBody
    @ExceptionHandler(Exception.class)
    public WebServiceMessage exceptionHandler(Exception e) {
        log.error("警告！！！程序出现异常", e);
        return WebServiceMessage.error(WebCodeEnum.ERROR);
    }
}
